package itbour.onetouchshow.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class CircleCanvas extends View {
    //  保存绘制历史
    public List<CircleInfo> mCircleInfos = new ArrayList<CircleInfo>();

    public CircleCanvas(Context context) {
        this(context, null);
    }

    public CircleCanvas(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CircleCanvas(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    //  当画布重绘时调用该方法，Canvas表示画布对象，可以在该对象上绘制基本的图形
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //  根据保存的绘制历史重绘所有的实心圆
        for (CircleInfo circleInfo : mCircleInfos) {
            Paint paint = new Paint();
            //  设置画笔颜色
            paint.setColor(circleInfo.getColor());
            //  绘制实心圆
            canvas.drawCircle(this.getWidth() / 2, this.getHeight() / 2, circleInfo.getRadius(), paint);
        }
    }

    // 保存实心圆相关信息的类
    public static class CircleInfo {
        private float x;                //  圆心横坐标
        private float y;                //  圆心纵坐标
        private float radius;            //  半径
        private int color;            //  画笔的颜色

        public float getX() {
            return x;
        }

        public void setX(float x) {
            this.x = x;
        }

        public float getY() {
            return y;
        }

        public void setY(float y) {
            this.y = y;
        }

        public float getRadius() {
            return radius;
        }

        public void setRadius(float radius) {
            this.radius = radius;
        }

        public int getColor() {
            return color;
        }

        public void setColor(int color) {
            this.color = color;
        }
    }
}